{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "有时候不需要输出Char，这个时候甚至可以直接把这个Char当作Int来使用。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def name_to_int(name):\n",
    "    result = 0\n",
    "    for char in name:\n",
    "        if char.isdigit():  # 检查字符是否为数字\n",
    "            result = result * 10 + int(char)  # 数字直接乘以10然后加上下一个数字\n",
    "        else:\n",
    "            # 字母转换为对应的数值（A=1, B=2, ..., Z=26）\n",
    "            result = result * 26 + (ord(char.upper()) - ord('A') + 1)\n",
    "    return result\n",
    "\n",
    "# 假设有一个学生姓名 \"ABC4\"\n",
    "student_name = \"ABC4\"\n",
    "student_int = name_to_int(student_name)\n",
    "print(student_int)  # 输出转换后的整数"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
